﻿using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Collections;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using SumGam.Globals;
using SumGam.Structs;
using SumGam.Classes;

namespace SumGam
{
    class TestEntity : BaseEntity
    {
        public TestEntity(Vector2 Position, Vector2 Velocity)
        {
            Initialized = false;
            Physical = true;
            Visible = true;
            ShouldRemove = false;
            this.Position = Position;
            this.Velocity = Velocity;
            this.Sprite = new AnimatedTexture(new Vector2(0f, 0f), 0, 1, 0);
            this.Sprite.Load(GameServices.Content, "GARY", 3, 10);
            this.Width = Sprite.Width / Sprite.FrameCount;
            this.Height = Sprite.Height;
            this.Height = Height;
            this.Origin = new Vector2(Width / 2, Height / 2);
            this.Sprite.Origin = this.Origin;
        }
        public override void Initialize()
        {
            Sprite.Reset();
        }
        public override void Think()
        {
            Vector2 NewVelocity = new Vector2();
            if (Helpers.GetKeyState(Keys.Up).IsDown)
            {
                NewVelocity.Y -= 0.5f;
            }
            if (Helpers.GetKeyState(Keys.Down).IsDown)
            {
                NewVelocity.Y += 0.5f;
            }
            if (Helpers.GetKeyState(Keys.Left).IsDown)
            {
                NewVelocity.X -= 0.5f;
            }
            if (Helpers.GetKeyState(Keys.Right).IsDown)
            {
                NewVelocity.X += 0.5f;
            }
            Sprite.UpdateFrame((float) Misc.Time.ElapsedGameTime.TotalSeconds);
            Velocity = NewVelocity;
        }
        public override void DoPhysics()
        {
            Position += Velocity;
        }
        public override void HandleCollision(BaseEntity Entity)
        {
            Velocity *= -1;
            DoPhysics();
        }
        public override void Draw()
        {
            Sprite.DrawFrame(Rendering.spriteBatch, Position);
        }

    }
}
